package com.ruoyi.sl.controller;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.sl.domain.SlMonthPay;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlMonthWs;
import com.ruoyi.sl.service.ISlMonthWsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车间工资Controller
 * 
 * @author admin
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/sl/monthws")
public class SlMonthWsController extends BaseController
{
    @Autowired
    private ISlMonthWsService slMonthWsService;

    /**
     * 查询车间工资列表
     */
    @PreAuthorize("@ss.hasPermi('sl:monthws:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlMonthWs slMonthWs)
    {
        startPage();
        List<SlMonthWs> list = slMonthWsService.selectSlMonthWsList(slMonthWs);
        return getDataTable(list);
    }

    /**
     * 条件查询车间工资列表
     */
    @PreAuthorize("@ss.hasPermi('sl:monthws:list')")
    @GetMapping("/rangelist")
    public TableDataInfo rangelist(SlMonthWs slMonthWs)
    {
        startPage();
        List<SlMonthWs> list = slMonthWsService.selectSlMonthWsListByRange(slMonthWs);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('sl:monthws:query')")
    @GetMapping("/singlelist")
    public TableDataInfo singlelist(SlMonthWs slMonthWs)
    {
        startPage();
        slMonthWs.setUserName(getLoginUser().getUsername());
        List<SlMonthWs> list = slMonthWsService.selectSlMonthWsListByRange(slMonthWs);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('sl:monthws:query')")
    @GetMapping("/mpaylist")
    public AjaxResult mpaylist(SlMonthWs slMonthWs)
    {
        AjaxResult ajax = AjaxResult.success();
        slMonthWs.setUserName(getLoginUser().getUsername());
        List<SlMonthPay> list = slMonthWsService.selectFusionMonthPay(slMonthWs);
        ajax.put(AjaxResult.DATA_TAG, list);
        return ajax;
    }


    /**
     * 导出车间工资列表
     */
    @PreAuthorize("@ss.hasPermi('sl:monthws:export')")
    @Log(title = "车间工资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlMonthWs slMonthWs)
    {
        List<SlMonthWs> list = slMonthWsService.selectSlMonthWsList(slMonthWs);
        ExcelUtil<SlMonthWs> util = new ExcelUtil<SlMonthWs>(SlMonthWs.class);
        util.exportExcel(response, list, "车间工资数据");
    }

    /**
     * 获取车间工资详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:monthws:query')")
    @GetMapping(value = "/{wsmpayId}")
    public AjaxResult getInfo(@PathVariable("wsmpayId") Long wsmpayId)
    {
        return success(slMonthWsService.selectSlMonthWsByWsmpayId(wsmpayId));
    }

    /**
     * 新增车间工资
     */
    @PreAuthorize("@ss.hasPermi('sl:monthws:add')")
    @Log(title = "车间工资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlMonthWs slMonthWs)
    {
        return toAjax(slMonthWsService.insertSlMonthWs(slMonthWs));
    }

    /**
     * 修改车间工资
     */
    @PreAuthorize("@ss.hasPermi('sl:monthws:edit')")
    @Log(title = "车间工资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlMonthWs slMonthWs)
    {
        return toAjax(slMonthWsService.updateSlMonthWs(slMonthWs));
    }

    /**
     * 删除车间工资
     */
    @PreAuthorize("@ss.hasPermi('sl:monthws:remove')")
    @Log(title = "车间工资", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wsmpayIds}")
    public AjaxResult remove(@PathVariable Long[] wsmpayIds)
    {
        return toAjax(slMonthWsService.deleteSlMonthWsByWsmpayIds(wsmpayIds));
    }
}
